/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Cliente.Vista;
import Cliente.Vista.Language.Constantes;
import java.util.Observable;
import java.util.Observer;
import javax.swing.ImageIcon;
import Cliente.Modelo.BoardPlaying;
import Cliente.Modelo.BoardPlaying;
/**
 *
 * @author Raquel Marin de Consuegra Dominguez
 * Class of Dice
 */
public class dice extends javax.swing.JPanel implements Observer{
BoardPlaying datePlayer = new BoardPlaying();
// necesito saber en que tablero estoy. Necesito saber si los dados son del jugador 1, 2...
// para poder dejarle que tire
    int dicePlayer = 0;
    
    // to select the dice
   public ImageIcon  saveDice (int num)
{
        ImageIcon icoImagen = null;
 switch (num)
 {
     case 1:
         icoImagen = new ImageIcon(Constantes.RUTA_1);
         break;
     case 2:
         icoImagen = new ImageIcon(Constantes.RUTA_2);
         break;
     case 3:
         icoImagen = new ImageIcon(Constantes.RUTA_3);
         break;
     case 4:
         icoImagen = new ImageIcon(Constantes.RUTA_4);
         break;
     case 5:
         icoImagen = new ImageIcon(Constantes.RUTA_5);
         break;
     case 6:
         icoImagen = new ImageIcon(Constantes.RUTA_6);
         break;
 }
 return icoImagen;
}
/**
 * When the player whose turn it is in a box less than 60 changes setVisible to false
 */
   public void oneDice ()
   {
       // where is the player box
       int box = 0;
       
       box = datePlayer.dame_casilla(datePlayer.getPlayerTurn());
       if (box >= 60)
       {dice2.setVisible(false);
       }
   }
   
   
   
   
    ImageIcon icon1 = new ImageIcon ();
    ImageIcon icon2 = new ImageIcon ();
    
    
    /**
     * Creates new form Dice
     */
    public dice() {
        initComponents();
        icon1= saveDice (1);
        icon2= saveDice (1);
        dice2.setIcon(icon1);
        dice3.setIcon(icon2);
         setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dice2 = new javax.swing.JLabel();
        dice3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setBackground(new java.awt.Color(0, 153, 204));

        jButton1.setBackground(new java.awt.Color(153, 0, 153));
        jButton1.setText(Constantes.PLAY_DICE);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(dice2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(50, 50, 50)
                        .addComponent(dice3, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(58, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dice3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dice2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        oneDice ();
        
   
        int numDice1 = datePlayer.getRoll_dice1();
        int numDice2 = datePlayer.getRoll_dice2();
        if (datePlayer.getPlayerTurn()== dicePlayer)
        {
        jButton1.setEnabled(true);
        dice2.setIcon(saveDice(numDice1));
        dice3.setIcon(saveDice(numDice2));
        }
        else {
            jButton1.setEnabled(false);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel dice2;
    private javax.swing.JLabel dice3;
    private javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables

     @Override
    public void update(Observable o, Object arg) {
        datePlayer = (BoardPlaying)arg;
        
       

        
    }
    
    }

